<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/vue.js"></script>
    <style>
        *{
            margin: 0;
            padding: 0;
            list-style: none;
        }
        .menu{
            display: flex;
            height: 40px;
        }
        .menu .item {
            flex: 1;
            height: 40px;
            text-align: center;
            line-height: 40px;
            background-color: black;
            color: burlywood;
        }
        .menu .active{
            color: red;;
        }
    </style>

</head>

<body>
    <div id="app">
        <div class="menu">
            <div class="item" v-for="item in list" :class="{active:item.id==activeIndex}" @click="change(item)">
                {{item.msg}}
            </div>
        </div>
        <div class="box">
            <component :is="com"></component>
        </div>
       
    </div>
</body>
<template id="com1">
    <div>
        我是组件一
    </div>
</template>
<template id="com2">
    <div>
        我是组件二
    </div>
</template>
<template id="com3">
    <div>
        我是组件三
    </div>
</template>
<script>
    let com1 = {
        template: "#com1"
    };
    let  com2={
        template:"#com2"
    }
    let  com3={
        template:"#com3"
    }
    new Vue({
        el: "#app",
        data: {
            com:"com1",
            activeIndex:1,
            list:[{id:1,msg:"父传子",com:"com1"},{id:2,msg:"子传父",com:"com2"},{id:3,msg:"子传子",com:"com3"}]
        },
        components: {
           com1,
           com2,
           com3
        },
        methods:{
            change(item){
                this.activeIndex = item.id;
                this.com = item.com;
            }
        }
    })

</script>

</html>